<?php
/**
 * @Name 部门
 * @Description
 * @Auther zsx
 * @Date 2023/3/1 15:21
 */

namespace app\controller;


use app\common\BaseController;
use app\service\DepartmentService;
use think\Request;

class DepartmentController extends BaseController
{
  /**
   * @Name 获取部门
   * @Description
   * @Author zsx
   * @Date 2023/3/1 15:22
   * @Method GET
   * @Return JSON
   **/
  public function index(Request $request)
  {
    $page = $request->param('page', 1);
    $pageSize = $request->param('pageSize', 10);
    $list = DepartmentService::getInstance()->getDepartmentByCondition();
    // 分页
    $count = count($list); //总条数
    $start=intval(($page - 1) * $pageSize); //偏移量，当前页-1乘以每页显示条数
    $pager = [
      'totalCount' => $count,
      'pageSize' => intval($pageSize),
      'currPage' => intval($page),
      'totalPage' => intval($count/$pageSize)+1
    ];
    $data = array_slice($list, $start, intval($pageSize));
    return $this->send200ResponseWithPager($data,$pager);
  }
}